#include <iostream>
using namespace std;

class Array
{
public:
    // 构造函数
    Array(int count) {
        this->count = count;
        Arr = new int[count];
        cout << "Array()" << endl;
    }
    // 拷贝构造函数
    Array(const Array & arr) {
        // 深拷贝
        this->count = arr.count;
        this->Arr = new int[count];
        for (int i = 0; i < count; i++) {
        this->Arr[i] = arr.Arr[i];
    }
        cout << "Array(const Array & arr)" << endl;
    }
    // 析构函数
    ~Array() {
        delete[]Arr;
        Arr = nullptr;
        cout << "~Array(): " << count << endl;
    }
    void printAddress(){
        cout<<"address:"<<Arr<<endl;
    }

    void setCount(int count) { this->count = count; }
    int getCount() { return count; }
private:
    int count;
    int *Arr;
};

// 栈上实例化
void stackInstantiation()
{
    Array arr1(6);
    arr1.setCount(5);
    // Array arr1(5);
    // 调用拷贝构造函数
    // Array arr2 = arr1;
    Array arr2(arr1);
   // arr2.setCount(5);
    Array arr3(arr2);
    Array arr4(arr3);
    arr1.printAddress();
    arr2.printAddress();
    arr3.printAddress();
    arr4.printAddress();
}

int main()
{
    stackInstantiation();
    return 0;
}